package com.zhaojiu.example.service.beetl.function;

import org.beetl.core.Context;
import org.beetl.core.Function;

import java.util.List;

/**
 * @author huangshb
 * @date 2024/8/5
 */
public class ToJavaType implements Function {
    @Override
    public Object call(Object[] paras, Context ctx) {
        Object o = paras[0];
        if (o == null) {
            return "Object";
        }
        if (o instanceof List) {
            for (Object o1 : (List<?>) o) {
                if (!o1.toString().equalsIgnoreCase("null")) {
                    return o1.toString().equalsIgnoreCase("string") ? "String" : "Object";
                }
            }
        }
        String s = o.toString();
        switch (s.toUpperCase()) {
            case "INTEGER":
                return "Integer";
            case "LONG":
                return "Long";
            case "FLOAT":
                return "Float";
            case "DOUBLE":
                return "Double";
            case "BOOLEAN":
                return "Boolean";
            case "DATE":
                return "Date";
            case "ARRAY":
                return "List<String>";
            default:
                return "String";
        }
    }
}
